using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace TuMama
{
    public static class ByteMensaje
    {
        public static byte[] GetBytes(Mensaje waga)
        {

            MemoryStream ms = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(ms, waga);
            return ms.ToArray();
        }

        public static Mensaje GetMensajeObject(byte[] Bytes)
        {
            MemoryStream ms = new MemoryStream();
            ms.Write(Bytes, 0, Bytes.Length);
            ms.Position = 0;
            BinaryFormatter formatter = new BinaryFormatter();
            return formatter.Deserialize(ms) as Mensaje;
        }
    }
}
